#include <bits/stdc++.h>

#define int long long

using namespace std;

void solve()
{
    int x,n;
    cin >> x >> n;
    if(n % 2 == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << x << endl;
    }
}

signed main()
{
    int t;
    cin >> t;
    while(t --)
    {
        solve();
    }
}